﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Workflow.Alerts.Interfaces.ProfileSettings;
using Sitecore.Data.Items;

namespace Workflow.Alerts.Sublayouts.ProfileSettings
{
    public partial class MaterialsList : BaseControl, IMaterialsListView
    {
        #region Properties
        public string Path
        {
            set
            {
                DetailsPath.Value = value;
            }
        }
        #endregion

        #region IMaterialsListView Members

        public System.Data.DataTable Materials
        {
            set
            {
                RadGrid1.DataSource = value;
                RadGrid1.DataBind();
            }
        }

        public event OnMaterialsListViewLoad OnPageLoad;

        #endregion

        #region Events
        protected void btnNew_Click(object sender, EventArgs e)
        {
            Item detailPageItem = Sitecore.Context.Item.Axes.GetChild("New Materials");
            var path = Sitecore.Links.LinkManager.GetItemUrl(detailPageItem);
            Response.Redirect(path);
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            RadGrid1.MasterTableView.ExportToExcel();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Item detailPageItem = Sitecore.Context.Item.Axes.GetChild("Materials Details");
            Path = Sitecore.Links.LinkManager.GetItemUrl(detailPageItem);

            PresentationManager.RegisterView(typeof(MaterialsListPresenter), this, new WebSessionProvider());
            if (OnPageLoad != null)
            {
                OnPageLoad();
            }
        }
        #endregion
    }
}